package math.probability;

import java.util.ArrayList;
import java.util.Random;

public class NormalDistribution extends ProbDistribution {
	private Double a;
	private Double s2;
	
	public NormalDistribution(Double a, Double s2) {
		this.a = a;	
		this.s2 = s2;
	}
	
	public NormalDistribution() {
		this.a = 0.0;	
		this.s2 = 1.0;
	}
	
	
	public ArrayList<Double> getSample(int n) {
		Random r = new Random();
		ArrayList<Double> sample = new ArrayList<Double>();
		for (int i = 0; i < n; i++) {
			sample.add(a + r.nextGaussian()*Math.sqrt(s2));
		}
		return sample;
	}
	
	public ArrayList<Double> getSample(int n, Random r) {
		ArrayList<Double> sample = new ArrayList<Double>();
		for (int i = 0; i < n; i++) {
			sample.add(a + r.nextGaussian()*Math.sqrt(s2));
		}
		return sample;
	}
	
	public String toString() {
		return "N("+String.format("%2.2f", a) + ";" +String.format("%2.2f", s2) +")";
	}

	@Override
	public Double getNext() {
		// TODO Auto-generated method stub
		Random r = new Random();
		return a + r.nextGaussian()*Math.sqrt(s2);
	}
	
	public Double getNext(Random r) {
		// TODO Auto-generated method stub
		return a + r.nextGaussian()*Math.sqrt(s2);
	}
	
	public Double getDisp() {
		return s2;
	}
}
